package com.example.figurehecheng.controller.merchant;


import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.RestaurantDTO;
import com.example.figurehecheng.domain.vo.RestaurantVO;
import com.example.figurehecheng.service.IRestaurantService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 餐厅表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-04
 */
@RestController("adminRestaurantController")
@RequestMapping("/admin/restaurant")
@CrossOrigin
@RequiredArgsConstructor
public class RestaurantController {
    @Autowired
    private IRestaurantService restaurantService;
    /**
     * 创建餐厅
     * @param dto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation("创建餐厅")
    public Result<Long> createRestaurant(@RequestBody @Valid RestaurantDTO dto){
        Long restaurantId = restaurantService.createRestaurant(dto);
        return Result.success(restaurantId);
    }

    /**
     * 获取商家餐厅列表
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("获取商家餐厅列表")
    public Result<List<RestaurantVO>> getRestaurantList(){
        List<RestaurantVO> list = restaurantService.getRestaurantListByMid();
        return Result.success(list);
    }
    /**
     * 获取商家餐厅详情
     * @return
     */
    @GetMapping("/info")
    @ApiOperation("获取商家餐厅详情")
    public Result<RestaurantVO> getRestaurantInfo(){
        RestaurantVO restaurantVO = restaurantService.getRestaurantByMid();
        return Result.success(restaurantVO);
    }
    /**
     * 修改餐厅信息
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改餐厅信息")
    public Result<Boolean> updateRestaurant(@RequestBody @Valid RestaurantDTO dto){
        boolean result = restaurantService.updateRestaurant(dto);
        return Result.success(result);
    }
}
